// ==UserScript==
// @name         央视网
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  提供央视网视频下载功能
// @author       You
// @match        *://*.cctv.com/*
// @icon         
// @grant        GM_xmlhttpRequest
// @grant        GM_setClipboard
// @grant        unsafeWindow
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';
    let domain = 'https://dh5.cntv.lxdns.com/';
    let guid;
    setTimeout(() => {
      guid = unsafeWindow.window.guid;
      if (!guid) { return; }
      console.log('guid=', guid);
      
    }, 2000);
    let button = document.createElement('button');
    button.style.cssText = `position:fixed;left:0;top:40%;width:30px;height:30px;cursor:pointer;z-index:9999999;border-radius:4px;`;
    button.innerHTML = `<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3662" width="20" height="20"><path d="M828.975746 894.125047 190.189132 894.125047c-70.550823 0-127.753639-57.18542-127.753639-127.752616L62.435493 606.674243c0-17.634636 14.308891-31.933293 31.93227-31.933293l63.889099 0c17.634636 0 31.93227 14.298658 31.93227 31.933293l0 95.821369c0 35.282574 28.596292 63.877843 63.87682 63.877843L765.098927 766.373455c35.281551 0 63.87682-28.595268 63.87682-63.877843l0-95.821369c0-17.634636 14.298658-31.933293 31.943526-31.933293l63.877843 0c17.634636 0 31.933293 14.298658 31.933293 31.933293l0 159.699212C956.729385 836.939627 899.538849 894.125047 828.975746 894.125047L828.975746 894.125047zM249.938957 267.509636c12.921287-12.919241 33.884738-12.919241 46.807049 0l148.97087 148.971893L445.716876 94.89323c0-17.634636 14.300704-31.94762 31.933293-31.94762l63.875796 0c17.637706 0 31.945573 14.312984 31.945573 31.94762l0 321.588299 148.97087-148.971893c12.921287-12.919241 33.875528-12.919241 46.796816 0l46.814212 46.818305c12.921287 12.922311 12.921287 33.874505 0 46.807049L552.261471 624.930025c-1.140986 1.137916-21.664416 13.68365-42.315758 13.69286-20.87647 0.010233-41.878806-12.541641-43.020816-13.69286L203.121676 361.13499c-12.922311-12.933567-12.922311-33.884738 0-46.807049L249.938957 267.509636 249.938957 267.509636z" fill="#272636" p-id="3663"></path></svg>`;
    document.documentElement.appendChild(button);
    button.onclick = () => {
      if(!guid){alert('guid not found!');return;}
      $X.ajaxPro("GET", "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=" + guid).then(v=>{
          let res = JSON.parse(v);
          console.log(res);
          let name = res.title;
          let url = res.hls_url;
          $X.ajaxPro('GET',domain+'asp/h5e'+url.slice(url.indexOf('/hls/'))).then(v=>{
            let ls = v.split('\n');
            ls.shift();
            ls[ls.length-1].length<10 && ls.pop();
            let str = 'Input a number to choose quality:\n\n';
            let m = ls.length/2;
            for(let i=0;i<m;i++){
                str+=`${i+1}: ${ls[2*i].slice(32)}\n`;
            }
            let n = prompt(str,m);
            n = parseInt(n);
            if(n>0 && n<=m){
                let uri = domain+ls[n*2-1];
                $X.runcmd(`N_m3u8DL-CLI_v3.0.2 "${uri}" --workDir "D:\\Download\\Video" --saveName "${name}" --maxThreads "24" --minThreads "8" --retryCount "20" --timeOut "3" --enableMuxFastStart`);
            }
          }).catch(v=>{
            alert('Failed getting m3u8 list:\n'+v)
          })
      }).catch(v=>{
          alert('Failed getting basic info:\n'+v);
      })
    }
  })();
// ADblock
/* 
iupac.org##header.masthead:first-child > div.container:first-child
ptable.com###NoticeText
ptable.com###Notice > ins.adsbygoogle:first-child
ptable.com##.Notice
jb51.net###txtlink
jb51.net###container > div.pt10.clearfix:first-child > div.clearfix > div.topimg:nth-child(5)
jb51.net###container > div.pt10.clearfix:first-child > div.clearfix > div.topimg:nth-child(9)
tvbxx.com###show_img-2377029035902478992-18117
www.tvbvv.com/statics/js/bq.js
www.tvbxx.com/statics/js/bq.js
www.tvbvv.cc/bq.html
www.tvbvv.cc/statics/js/bq.js
m.tvbvv.com/statics/js/bq.js
m.tvbxx.com/statics/js/bq.js
m.tvbvv.cc/bq.html
m.tvbvv.cc/statics/js/bq.js
link.csdn.net
powerline.io###mobileBoxId
powerline.io###firstRightBox
zh.wikipedia.aufe.cf###soundlogoreghref2 > div.frb-inline-main:last-child
zh.wikipedia.aufe.cf###advancedSiteNotices
zh.wikipedia.aufe.cf###asn-dismissable-notice
www.psy.net.cn/pingbi.js
ncbi.nlm.nih.gov###universal_header > header.ncbi-header:nth-child(3)
ncbi.nlm.nih.gov###universal_header > section.usa-banner:first-child > div.usa-accordion > header.usa-banner-header:first-child > div.usa-grid.usa-banner-inner
pubmed.ncbi.nlm.nih.gov##header.ncbi-header:nth-child(6)
jingyan.baidu.com###format-exp > div.read-whole-mask:last-child > div.exp-mask:first-child
jingyan.baidu.com###format-exp > div.read-whole-mask:last-child
easylearn.baidu.com###app > div.page > div:first-child > div > div.container:last-child > div.left:first-child > div.question-cont > div.shijuan-cont:nth-child(6)
easylearn.baidu.com###app > div.page > div:first-child > div > div.container:last-child > div.left:first-child > div.question-cont > div.shiti-answer:last-child > div.text:last-child > div.mask:last-child
php.cn##div.bottom_vue:nth-child(5) > div.vue_img:first-child
php.cn##div.bottom_vue:nth-child(5) > a.vue-hide:last-child
php.cn##div.layui-layer.layui-layer-iframe
php.cn##div.layui-layer-content
php.cn##div.phpCeNav
php.cn##.wwads-cn, .wwads-vertical, .wwads-sticky
blog.csdn.net###kp_box_57 > iframe:first-child
aiqicha.baidu.com###floatBannerMark
runoob.com###footer > div.runoob-block:first-child
runoob.com###footer > div.w-1000.copyright:last-child
developer.mozilla.org###root > div.page-wrapper.document-page:nth-child(2) > div.container:nth-child(2) > div.notecard.localized-content-note.neutral
bilibili.com###i_cecream > div.adblock-tips:nth-child(2)
pk.baicizhan.com###download_button_download_button_47D_r
https://7n.bczcdn.com/challenge/sounds/bgm.mp3
icourse163.org###j-learningState-container > div.coupon
icourse163.org###j-activityBanner
qianduanheidong.com###layui-layer-shade1
qianduanheidong.com###layui-layer1
haokan.baidu.com###passport-login-pop-dialog > div.clearfix > div.pass-login-pop-content
haokan.baidu.com###TANGRAM__PSP_5__ > iframe:first-child
haokan.baidu.com###TANGRAM__PSP_5__
haokan.baidu.com###art-player-wrapper > div.player-pause-code
www.315kc.com/wg.html
www.315kc.com/public/tpl/41ys/js/jquery-3.4.1.min.js
www.315kc.com/public/tpl/41ys/js/jquery.lazyload.min.js
max.book118.com###sidebar > div.integral:first-child > a.sidebar-item-on
max.book118.com###sidebar > ul.list
max.book118.com##.webpreview-recommend
max.book118.com###main .webpreview-split
max.book118.com##.webpreview-split
ncjy.net###container > div.row.row-detail.row-reader > div.layout.layout-col1 > div.reader-main:last-child > div:nth-child(4)
ncjy.net###container > div.row.row-detail.row-reader > div.layout.layout-col1 > div.reader-main:last-child > a.btn-addbs:nth-child(5)
ncjy.net##div.topbar:nth-child(6)
ncjy.net###content > div.posterror:first-child
ncjy.net###footer > div.pc-footer:first-child
x218zw.com###wrapper > div.ywtop:first-child
x218zw.com###content > div:last-child
ncjy.net##figure.MDkwOQ.aznav:nth-child(11)
map.baidu.com###cards-level2 > div.poiLeadDownloadCard
map.baidu.com###ui3_springfestival_data > div.ui3-springfestival-data-link
programiz.com##div.main--backdrop.show:first-child
programiz.com##main.soft-bg.fixed-nav:nth-child(2) > footer.footer:last-child > div.pop-up-block.d-flex:nth-child(4)
programiz.com##main.fixed-nav > footer.footer> div.pop-up-block.d-flex
guangzan.gitee.io
cnblogs.com###div_digg
532movie.bnu.edu.cn###video > div.dplayer-menu.dplayer-menu-show:nth-child(6) > div.dplayer-menu-item > a
532movie.bnu.edu.cn###video > div.dplayer-menu.dplayer-menu-show
yixuemao.com##header.yxm_nav_fix:nth-child(2) > div.yxm_top_02
kaoyan.com###J_floatQrcode > img.left-img:nth-child(2)
kaoyan.com###DL_bottom
kaoyan.com###J_floatQrcode_close
publish.obsidian.md/lib/pixi.min.js
google.com/*
www.google-analytics.com/analytics.js
programmercarl.com###app > div.theme-container:first-child > header.navbar:first-child
programmercarl.com###app > div.theme-container:first-child > aside.page-sidebar:last-child
learn.microsoft.com###disclaimer-holder > section.is-info.alert.is-banner > div.uhf-container > div.columns:last-child > div.column.is-12 > div.level.justify-content-flex-start
learn.microsoft.com###disclaimer-holder > section.is-info.alert.is-banner
wolframalpha.com###__next > div.__trY > div.sc-60840a14-0.ctuLqV:nth-child(3) > main._26mq > span.sc-b36f146e-0.jThirh:first-child > a._3BQD._dGJe._ZJzB.sc-34cb55e4-2.sc-34cb55e4-3.cwjaCb.kPdgYi.sc-613dfdea-0.dHdZCx
wolframalpha.com###__next > div.__trY > div.sc-60840a14-0.ctuLqV:nth-child(3) > main._26mq > span.sc-d2f07b46-0.dfCwWB:first-child > a._3BQD._dGJe._ZJzB.sc-34cb55e4-2.sc-34cb55e4-3.cwjaCb.kPdgYi.sc-613dfdea-0.uZCMw
bilibili.com###biliMainHeader > div.bili-header.fixed-header > div.bili-header__bar.mini-header > ul.left-entry:first-child > li.v-popover-wrap:last-child
bilibili.com###i_cecream > div.bili-feed4:last-child > div.bili-header.large-header:first-child > div.bili-header__bar:first-child > ul.left-entry:first-child > li.v-popover-wrap:last-child
stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css
neuroscience.zju.edu.cn##div.fixed-link:nth-child(16)
wenku.baidu.com###app-reader-editor-below
stackoverflow.com##div.ff-sans.ps-fixed.z-nav-fixed
stackoverflow.com###noscript-warning
learn.microsoft.com###banner-holder
gitee.com##div.gitee-stars-main-widget
tinymind.net.cn###layui-layer-shade1
tinymind.net.cn###layui-layer1


WHITE LIST
aliyundrive.com
colab.research.google.com
accounts.google.com
bilibili.com

*/